package org.dromara.house.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.house.domain.bo.ParkTenantBo;
import org.dromara.house.domain.entity.ParkTenant;
import org.dromara.house.service.ParkTenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 园区租户信息主表 前端控制器
 * </p>
 *
 * @author LCH
 * @since 2025-08-26
 */
@RestController
@RequestMapping("/park/tenant")
public class ParkTenantController extends BaseController {


    @Autowired
    private ParkTenantService service;

    /**
     * 获取园区租户信息列表
     */
    @SaCheckPermission("park:tenant:list")
    @GetMapping("/list")
    public TableDataInfo<ParkTenant> list(ParkTenantBo bo, PageQuery pageQuery) {
        return service.selectPageList(bo, pageQuery);
    }

    /**
     * 获取园区租户信息列表
     */
    @SaCheckPermission("park:tenant:list")
    @GetMapping("/listAll")
    public R<List<ParkTenant>> list(ParkTenantBo bo) {
        LambdaQueryWrapper<ParkTenant> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(ObjectUtil.isNotEmpty(bo.getEnterpriseName()),ParkTenant::getEnterpriseName, bo.getEnterpriseName());
        wrapper.eq(ParkTenant::getIsDeleted,0);
        List<ParkTenant> list = service.list(wrapper);
        return R.ok(list);
    }


    /**
     * id获取详细信息
     */
    @SaCheckPermission("system:tenant:query")
    @GetMapping(value = "/{id}")
    public R<ParkTenant> getInfo(@PathVariable Long id) {
        return R.ok(service.selectById(id));
    }

    /* *
     * 新增园区租户信息
     */
    @SaCheckPermission("system:tenant:add")
    @Log(title = "园区租户信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody ParkTenant parkTenant) {
        return toAjax(service.insertParkHousing(parkTenant));

    }

    /* *
     * 修改园区租户信息
     *
     */
    @SaCheckPermission("system:tenant:edit")
    @Log(title = "园区租户信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public R<Void> edit(@Validated @RequestBody ParkTenant parkTenant) {
        return toAjax(service.updateParkHousing(parkTenant));
    }


    /**
     * 删除园区租户信息
     **/
    @SaCheckPermission("system:tenant:remove")
    @Log(title = "园区租户信息管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(service.deleteByIds(ids));
    }
}

